<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * This controller will control the home page of the site.
 */
class Home extends CI_Controller {

  // calling the parent construct
  public function __construct() {
    parent::__construct();
//    $this->output->enable_profiler(TRUE);
		$this->cache = $this->boost->get_boost_cache();
  }

  // index function
  public function index() {
		if (!$this->cache) {
			$this->load->model('page_model', 'page');

			// getting the pagination settings
			$this->load->library('pagination');

			// adding the scripts

			$this->carabiner->js(array('subscription/sub_mod.js'));
			$this->carabiner->js(array('subscription/sub_app.js'));
			$this->carabiner->js(array('nodes/home_scripts.js'));

			// data content
			$data['header']['pagetitle'] = 'My blog - Tutorials on jQuery, PHP, Javascript';
			$data['header']['metaprop']['og:title'] = 'My blog - Tutorials on jQuery, PHP, Javascript';
			$data['header']['metaprop']['og:type'] = 'blog';
			$data['header']['metaprop']['og:url'] = 'http://amitavroy.com';
			$data['header']['metaprop']['og:image'] = 'https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-ash4/p206x206/1191_10151166502361065_316701282_n.jpg';
			$data['header']['metaprop']['og:site_name'] = 'Amitav Roy';
			$data['header']['metaprop']['og:description'] = 'Articles and blog posts on Web development - things that I like and RND on. Photography and Travel articles which I do when I am not working.';

			$data['content']['view'] = 'pages/landingpage';
			$data['content']['data']['attr'] = 'front';
			$data['content']['data']['nodes'] = $this->page->get_homepage_nodes();
			$data['content']['data']['nodes_count'] = $this->db->count_all('node');
			$data['content']['data']['more_url'] = 'pages/home/more'; // for pagination

			// loading the page layout
			$page_html = $this->load->view('pages/page',$data, true);
			$this->boost->set_boost_cache($page_html);
		}
  }

  public function more() {
    // adding the scripts
    $this->carabiner->js(array('subscription/sub_mod.js'));
    $this->carabiner->js(array('subscription/sub_app.js'));

    $pager = $this->uri->segment(4); // dsm($pager);

    $this->load->model('page_model', 'page');

    // getting the pagination settings
    $this->load->library('pagination');
    $config['base_url'] = base_url() . 'pages/home/more/';
    $config['total_rows'] = 37;
    $config['per_page'] = 10;
    $config['uri_segment'] = 4;
    $this->pagination->initialize($config);

    // data content
    $data['header']['pagetitle'] = 'My blog - Tutorials, jQuery, PHP, Javascript';
    $data['content']['view'] = 'pages/landingpage';
    $data['content']['data']['nodes'] = $this->page->get_homepage_nodes($pager);
    $data['content']['data']['nodes_count'] = $this->db->count_all('node');
    $data['content']['data']['more_url'] = 'pages/home/more'; // for pagination

    // loading the page layout
    $this->load->view('pages/page',$data);
  }
}
